<?php

namespace app\common;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use think\Exception;


class Sms
{


    /**
     * 校验验证码
     * @param int $mobile 手机号
     * @param int $captcha 验证码
     * @param string $event 事件 登录=login,注册=register,换绑手机号=changemobile,更改密码=changepwd,重置密码=resetpwd
     * @return  boolean
     * @throws Exception
     * @throws GuzzleException
     */
    public static function check($mobile, $captcha, $event = 'default')
    {
        $client = new Client();
        $ret = $client->post(env('ADMIN_HOST') . '/api/Sms/check', [
            'json' => [
                'mobile' => $mobile,
                'event' => $event,
                'captcha' => $captcha,
            ]
        ]);
        $ret = $ret->getBody()->getContents();
        $ret = json_decode($ret);
        if ($ret->code != 1) {
            throw new Exception($ret->msg);
        }
        return true;
    }

}